package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.CitiesQuery;
import com.xingkeduo.pojo.table.CitiesTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class CitiesService {
    private static final String NAMESPACE = CitiesTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<CitiesTable, CitiesQuery> dao;
    //查询一条
    public CitiesTable selectById(long id) throws Throwable {
        CitiesTable citiesTable = dao.select(NAMESPACE, id);
        return citiesTable;

    }
    //查询一条
    public CitiesTable selectByCode(long code) throws Throwable {
        CitiesTable citiesTable = dao.select(NAMESPACE, code);
        return citiesTable;

    }

    //查询多条
    public List<CitiesTable> selectLists(CitiesQuery citiesQuery) throws Throwable {
        List<CitiesTable> citiesTableList = dao.select(NAMESPACE, citiesQuery);
        if (!CommonUtil.isEmpty(citiesTableList))
            return citiesTableList;
        return null;
    }

    //分页查询
    public Page<CitiesTable> selectPageLists(CitiesQuery citiesQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<CitiesTable> citiesTablePage = dao.pageSelect(NAMESPACE,citiesQuery,pageNo,pageSize);
        return citiesTablePage;
    }

    //插入
    public int insert(CitiesTable citiesTable) throws Throwable {
        citiesTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, citiesTable);
    }

    //更新
    public int update(CitiesTable citiesTable) throws Throwable {
        return dao.update(NAMESPACE, citiesTable);
    }

    //删除
    public int delete(CitiesTable citiesTable) throws Throwable {
        return dao.update(NAMESPACE, citiesTable);
    }
    //总条数
    public int count(CitiesQuery citiesQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, citiesQuery);
    }
}
